package file;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 文件读取操作工具，获得文件内容.<BR>
 *
 *
 * VERSION        NAME        DATE        REASON
 * ----------------------------------------------------------------------------
 * 1.00           Brian       Feb 11, 2012  Create
 * @author brian
 * @version 1.00
 */
public class ReadFileUtil {

    private static int defaultCharBufferSize = 8192;

    /**
     * 获得文件所以行内容。<BR>
     * 
     * @param path
     * @return List String
     */
    public static List<String> getFileAllRow(String path) {

        List<String> lines = new ArrayList<String>();
        try {
            BufferedReader reader = new BufferedReader(new FileReader(path));
            String line = "";
            while ((line = reader.readLine()) != null) {
                lines.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("please check this path and file -->" + path);
        }
        return lines;
    }

    /**
     * 根据文件路径获得BufferedReader实例,使用8192大小的缓冲区.<BR>
     *
     * @param path
     * @return
     */
    public static BufferedReader getBufferedReader(String path) {

        return getBufferedReader(path, defaultCharBufferSize);
    }

    /**
     * 根据文件路径获得BufferedReader实例,并且使用size大小的缓冲区.<BR>
     *
     * @param path
     * @param size
     * @return
     */
    public static BufferedReader getBufferedReader(String path, int size) {

        try {
            return new BufferedReader(new FileReader(path), size);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            throw new RuntimeException("please check this path and file -->" + path);
        }
    }
}
